//*****************************************************************************
//  172x72 COG Display Temp. Comp. FW
//  MCU: MSP430F235
//  PCB: 10424
//  Compiler: TI Code Composer Essentials MSP430 v3.1
//  Kent Displays, Inc.
//  Copyright (c) 2009. All rights reserved worldwide.
//  Revisions
//     A - Initial. (24V Drive System, No Focal Conic Erase)
//     B - 28V Drive System, Focal Conic Erase
//*****************************************************************************

#include "defines.h"
#include "system.h"
#include "display.h"
#include "image.h"
#include "led.h"
#include "cal.h"
#include "GT22.h"
#include "packet_handl.h" 

// Wakeup source definitions.
typedef enum {RS232_WAKE, TIMER, SWITCH1} WakeupSources;

// Global Variables
volatile WakeupSources gWakeSource;    // Wakeup source (set by ISR's)

// Global variables.
volatile unsigned int gTimer;   // Used to extend HW 16 bit counter to 32 bits.

unsigned char Rx_Buffer = 0x00;

typedef enum {FAILED = 0, PASSED = !FAILED} TestStatus;

volatile TestStatus TransferStatus1 = FAILED;

TestStatus Buffercmp(unsigned char* pBuffer1, unsigned char* pBuffer2, unsigned int BufferLength);

volatile unsigned char rev_flag = 0;

#define receive_length 5 
unsigned char shangpingming[8] = {0xc8, 0xb8, 0xb3, 0xb2, 0xbf, 0xa7, 0xb7, 0xc8};
unsigned char jiage[5] = {3, 7, 0x0a, 6, 8};
unsigned char tiaoxingma[13] = {6, 9, 1, 7, 8, 7, 8, 0, 0, 7, 9, 7, 7};
unsigned char chandi[4] = {0xd0, 0xec, 0xd6, 0xdd};
unsigned char guige[6] = {0xa3, 0xb1, 0xa3, 0xb4, 0xa3, 0xb3};
unsigned char denji[2] = {0xa3, 0xc1};
unsigned char danwei[2] = {0xba, 0xd0};
void main()
{
	volatile unsigned int i = 0;
    volatile unsigned int j = 0;
	// System Initialization
	StopWatchdog();               // Stop watchdog timer.
	ConfigPorts();                // Configure I/O ports.
    
    P5SEL |= BIT4 + BIT5;                       // Port select XT1
    
	ConfigClocks();               // Configure basic clock module.
    
    GT_config();
    LED_config();
    LED1_set();
    

    _BIS_SR(GIE);

    volatile unsigned char ii = 20;
    
    while (ii --) {
        LED1_toggle();
        __delay_cycles(500000);
    }
    
    while (1) {    

     Clearn();

//    handl(RxBuf);

    Display( BitmapDot, 0, 0, 
        70000ul, 4000ul, 4, 80000ul, 7500ul, 2, 0 ,1, 101);
    __delay_cycles(5000000);
    }
}

#pragma vector=TIMER1_A0_VECTOR
__interrupt void TIMER1_A0_ISR(void)
{
	if (gTimer == 0)     // Timer started by SetTimer() expired?
	{
		TA1CTL &= ~(MC1 + MC0);  // Stop timer.
		TA1CCTL0 &= ~CCIE;       // Disable timer interrupt.
		
		// Disable all interrupts and wake from sleep on exit.
		__bic_SR_register_on_exit(GIE + LPM3_bits);
	}
	else   // Timer not yet expired.
	{
		gTimer -= 1;
	}
}

/*******************************************************************************
* Function Name  : Buffercmp
* Description    : Compares two buffers.
* Input          : - pBuffer1, pBuffer2: buffers to be compared.
*                : - BufferLength: buffer's length
* Output         : None
* Return         : PASSED: pBuffer1 identical to pBuffer2
*                  FAILED: pBuffer1 differs from pBuffer2
*******************************************************************************/
TestStatus Buffercmp(unsigned char* pBuffer1, unsigned char* pBuffer2, unsigned int BufferLength)
{
	while(BufferLength--)
  	{
    	if(*pBuffer1 != *pBuffer2)
    	{
      		return FAILED;
    	}
    
    	pBuffer1++;
    	pBuffer2++;
  	}

  return PASSED;  
}
